// package com.ww.sound_emission.config;
// import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
// import org.springframework.context.annotation.Bean;
// import org.springframework.context.annotation.Configuration;
// import org.springframework.integration.annotation.IntegrationComponentScan;
// import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
// import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
// import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
// import org.springframework.integration.channel.DirectChannel;
// import org.springframework.messaging.MessageChannel;
// import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
//
// @Configuration
// @IntegrationComponentScan
// public class MqttConfig {
//
//     @Bean
//     public MqttPahoClientFactory mqttClientFactory() {
//         DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
//
//         // 配置连接选项
//         MqttConnectOptions options = new MqttConnectOptions();
//         options.setServerURIs(new String[] { "tcp://192.168.5.126:1883" });  // 设置 Broker 地址
//         options.setUserName("admin");  // 如果有用户名，设置用户名
//         options.setPassword("admin123456".toCharArray());  // 如果有密码，设置密码
//
//         factory.setConnectionOptions(options);  // 将连接选项设置到工厂中
//         return factory;
//     }
//
//     @Bean
//     public MessageChannel mqttInputChannel() {
//         return new DirectChannel();
//     }
//
//     @Bean
//     public MqttPahoMessageDrivenChannelAdapter mqttInbound() {
//         MqttPahoMessageDrivenChannelAdapter adapter =
//                 new MqttPahoMessageDrivenChannelAdapter("my-client-id", mqttClientFactory(), "Probe/Mems/#");
//         adapter.setOutputChannel(mqttInputChannel());
//         return adapter;
//     }
//
//     @Bean
//     public MqttPahoMessageHandler mqttOutbound() {
//         MqttPahoMessageHandler handler = new MqttPahoMessageHandler("my-client-id", mqttClientFactory());
//         handler.setAsync(true);
//         handler.setDefaultTopic("Probe/Mems/#");
//         return handler;
//     }
// }
